package com.sjd.common.utils;

import org.apache.commons.lang3.RandomStringUtils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @ProjectName: sjd
 * @Package: com.sjd.common.utils
 * @ClassName: OrderNoUtils
 * @Author: genglong
 * @Description: 订单号工具类
 * @Date: 2022/1/11 14:00
 * @Version: 1.0
 */
public class OrderNoUtils {

    public static synchronized String generateOrderNo(String prefix){
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyMMddHHmmss");
        String localTime = LocalDateTime.now().format(dateTimeFormatter);
        String random = RandomStringUtils.randomNumeric(8);
        //前缀 + 日期时间 + random
        String orderNo = prefix + localTime + random;
        return orderNo;
    }

    /**
     * 订单类型
     */
    public interface OrderType {
        /**
         * 充值
         */
        String BILL_RECHARGE = "REC";

        /**
         * 消费
         */
        String BILL_CONSUME = "CON";

        /**
         * 退款
         */
        String BILL_REFOUND = "REF";

        /**
         * 农场消费
         */
        String FARM_CONSUME = "FCN";

    }
}
